package com.kms.monitor;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.Properties;

/**
 * 
 * @author adolfmc
 */
public class SystemMonitorInfo {
	static Runtime run = Runtime.getRuntime();
	Properties properties = System.getProperties();
	Map<String, String> map = System.getenv();

	public SystemMonitorInfo() {
		run = Runtime.getRuntime();
		properties = System.getProperties();
		map = System.getenv();
	}

	/** 操作系统. */
	private static String osName;
	private static String cupQuantity;
	private static String jvmversion;
	private static String jvmname;
	private static String host;
	/** 可使用内存. */
	private static long totalMemory;
	/** 剩余内存. */
	private static long freeMemory;
	/** 最大可使用内存. */
	private static long maxMemory;
	/** 总的物理内存. */
	private static long totalMemorySize;
	/** 剩余的物理内存. */
	private static long freePhysicalMemorySize;
	/** 已使用的物理内存. */
	private static long usedMemory;
	/** 线程总数. */
	private static int totalThread;
	/** cpu使用率. */
	private static double cpuRatio;

	public static String getOsName() {
		return System.getProperty("os.name")+" "+System.getProperty("os.version")+" ("+System.getProperty("os.arch")+")";
	}
	public static String getCupQuantity() {
		return System.getenv().get("NUMBER_OF_PROCESSORS");
	}
	public static String getJvmversion() {
		return "(JDK "+System.getProperty("java.specification.version")+") "+ System.getProperty("java.vm.version")+"("+System.getProperty("java.specification.vendor")+")";
	}
	public static String getJvmname() {
		return System.getProperty("java.vm.name");
	}
	public static String getHost()  {
		String host = "Unkown.";
		try {
			host = InetAddress.getLocalHost().toString();
		} catch (UnknownHostException e) {
		}
		return host;
	}
	public static long getFreeMemory() {
		return run.freeMemory();
	}

	public static long getFreePhysicalMemorySize() {
		return freePhysicalMemorySize;
	}

	public static long getMaxMemory() {
		return run.maxMemory();
	}

	public static long getTotalMemory() {
		return run.totalMemory();
	}

	public static long getTotalMemorySize() {
		return totalMemorySize;
	}

	public static int getTotalThread() {
		return totalThread;
	}

	public static long getUsedMemory() {
		return usedMemory;
	}

	public static double getCpuRatio() {
		return cpuRatio;
	}
	
}